package org.gpp.proj1.robot.action.step;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import junit.framework.TestCase;

import org.easymock.EasyMock;
import org.gpp.proj1.bone.Bone;
import org.gpp.proj1.robot.Robot;
import org.gpp.proj1.robot.modifier.Modifier;
import org.gpp.proj1.robot.part.EquippedPart;
import org.gpp.proj1.robot.part.PartType;
import org.gpp.proj1.robot.part.emissor.Emissor;

/**
 * @author Paolo Victor, paolovictor@gmail.com
 */
public class ChangeTargetAnimationActionStepTest extends TestCase {
	public void testChangeTargetAnimationActionStep() {
		// Animation name cannot be null
		try {
			new ChangeTargetAnimationActionStep( null );
			fail();
		} catch (AssertionError e) {
			// expected error
		}
		
		// Valid construct
		try {
			new ChangeTargetAnimationActionStep( "animation" );
		} catch (AssertionError e) {
			fail();
		}
	}
	
	public void testExecuteAction() {
		// Valid execution
		Robot robotMock = EasyMock.createMock( Robot.class );
		EquippedPart part = new EquippedPart( "testPart",
				PartType.HEAD,
				100,
				new HashMap<String, Integer>(),
				new LinkedList<Modifier>(),
				new HashMap<String, String>(),
				new HashMap<String, String>(),
				new LinkedList<Emissor>(),
				new LinkedList<String>(),
				robotMock,
				new HashMap<String, Bone>() );
		
		Robot targetMock1 = EasyMock.createMock( Robot.class );
		Robot targetMock2 = EasyMock.createMock( Robot.class );
		Robot targetMock3 = EasyMock.createMock( Robot.class );
		
		List<Robot> targets = new LinkedList<Robot>();
		
		targets.add( targetMock1 );
		targets.add( targetMock2 );
		targets.add( targetMock3 );
		
		ChangeTargetAnimationActionStep step = new ChangeTargetAnimationActionStep("hurt");
						
		EasyMock.reset( robotMock );
		targetMock1.setAnimation( EasyMock.eq( "hurt" ) ); EasyMock.expectLastCall().times( 1 ) ;
		targetMock2.setAnimation( EasyMock.eq( "hurt" ) ); EasyMock.expectLastCall().times( 1 ) ;
		targetMock3.setAnimation( EasyMock.eq( "hurt" ) ); EasyMock.expectLastCall().times( 1 ) ;
		EasyMock.replay( robotMock );
		
		step.execute( part, targets );
		
		EasyMock.verify( robotMock );
		
		// Invalid execution: null targets
		try {
			step.execute( part, null );	
		} catch (AssertionError e) {
			// expected error
		}
	}
}
